package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.ReplicationMySQLConnection;
import com.zr.d_c.model.Seller;
import com.zr.d_c.model.User;
import com.zr.d_c.service.UserInfoService;
import com.zr.d_c.service.UserService;
import com.zr.d_c.serviceimpl.UserInfoServiceImpl;
import com.zr.d_c.serviceimpl.UserServiceImpl;
/**
 * 卖家注册
 * @author Administrator
 *
 */
public class AddSellerController extends HttpServlet {
	User user = new User();
	Seller seller = new Seller();
	UserService userservice = new UserServiceImpl();
	UserInfoService userinfoservice = new UserInfoServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Date date = new Date();
		SimpleDateFormat datef  =new SimpleDateFormat("yyyy-MM-dd");

		String logname = req.getParameter("loguname");
		String logpsw = req.getParameter("logupsw");		
		user.setUname(logname);
		user.setUpsw(logpsw);
		int rid = 2;
		user.setRid(rid);
		int uisdelete =1;
		user.setUisdelete(uisdelete);	       
		seller.setSname(req.getParameter("regsname"));		
		seller.setSaddress(req.getParameter("regsaddress"));
		seller.setSphone(req.getParameter("regsphone"));
		seller.setSemail(req.getParameter("regsemail"));
		seller.setScreatetime(datef.format(date));
		seller.setStemp("1");
		PrintWriter pw = resp.getWriter();
		if (userservice.judgeUname(user.getUname())) {
			pw.write("0");
		}
		else {
			pw.write("1");
			if (userservice.addUserService(user)) {
				int uid =userservice.getUid(logname);
				seller.setUid(uid);
				userinfoservice.addSeller(seller);
			}





		}

	}
}
